
#include "SpaceShooter.h"
#include "defs.h"

std::vector<Object*> SpaceShooter::objectList;

SpaceShooter::SpaceShooter(){

	dispSurface = NULL;
	
	running = false;

	gameState = INGAME;

	enemySpawnTimer = 0;
}

int SpaceShooter::execute(){

	#ifdef	FRAME_LIMIT
		int frameTime;
	#endif
	
	if(!init())
		return -1;

	SDL_Event e;

	running = true;

	while(running)
	{
		#ifdef FRAME_LIMIT
			frameTime = SDL_GetTicks();
		#endif

		while(SDL_PollEvent(&e))
			Event::OnEvent(&e);

		loop();

		render();

		#ifdef	FRAME_LIMIT
			frameTime = SDL_GetTicks() - frameTime;

			if( frameTime < 1000 / FRAME_LIMIT )
				SDL_Delay( 1000 / FRAME_LIMIT - frameTime );

		#endif
	}

	cleanup();

	return 0;
}

Object* SpaceShooter::getPlayerShip(){
	if(objectList.size() > 0)
		return objectList[0];
	else
		return NULL;
}
